package net.lanelife.casino.caipiao.dto.admin;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import net.lanelife.casino.caipiao.entity.ActivityPrizeRecord;
import net.lanelife.casino.caipiao.entity.ActivityPrizeRecord_;
import net.lanelife.casino.common.dto.support.GenericTable;
import net.lanelife.casino.common.entity.json.serialize.CurrencySerializer;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;

/**
 * @author Lane
 * 
 * 活动礼金记录表格
 *
 * @param <DTO>
 */
public class ActivityPrizeRecordTable<DTO> extends GenericTable<DTO, ActivityPrizeRecord> {

	private static final long serialVersionUID = 5456401924282098153L;

	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountPending = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountAccepted = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountRejected = 0D;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double amountCancelled = 0D;
	
	public ActivityPrizeRecordTable() {}

	public ActivityPrizeRecordTable(Double amountPending,
			Double amountAccepted, Double amountRejected, Double amountCancelled) {
		super();
		this.amountPending = amountPending;
		this.amountAccepted = amountAccepted;
		this.amountRejected = amountRejected;
		this.amountCancelled = amountCancelled;
	}

	@Override
	public List<Selection<?>> buildExpression(Root<ActivityPrizeRecord> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
		List<Selection<?>> columns = Lists.newArrayList();
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(ActivityPrizeRecord_.status), ActivityPrizeRecord.Status.PENDING), root.<Double>get(ActivityPrizeRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(ActivityPrizeRecord_.status), ActivityPrizeRecord.Status.ACCEPTED), root.<Double>get(ActivityPrizeRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(ActivityPrizeRecord_.status), ActivityPrizeRecord.Status.REJECTED), root.<Double>get(ActivityPrizeRecord_.amount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(ActivityPrizeRecord_.status), ActivityPrizeRecord.Status.CANCELLED), root.<Double>get(ActivityPrizeRecord_.amount)).otherwise(0D)));
		return columns;
	}

	public Double getAmountPending() {
		return amountPending;
	}

	public void setAmountPending(Double amountPending) {
		this.amountPending = amountPending;
	}

	public Double getAmountAccepted() {
		return amountAccepted;
	}

	public void setAmountAccepted(Double amountAccepted) {
		this.amountAccepted = amountAccepted;
	}

	public Double getAmountRejected() {
		return amountRejected;
	}

	public void setAmountRejected(Double amountRejected) {
		this.amountRejected = amountRejected;
	}

	public Double getAmountCancelled() {
		return amountCancelled;
	}

	public void setAmountCancelled(Double amountCancelled) {
		this.amountCancelled = amountCancelled;
	}

}
